package shipNuking;

import java.io.IOException;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Scanner;

public class ThreadServer extends Thread {
	private ServerSocket serverSock;
	private Server server;
	
	public ThreadServer(ServerSocket serverSock, Server server){
		this.serverSock = serverSock;
		this.server = server;
	}
	public void run() {
		Socket client;
		
		try {
			client = this.serverSock.accept();
			Scanner in = new Scanner(client.getInputStream());
			PrintWriter out = new PrintWriter(client.getOutputStream(), true);

			while (!server.shipPlacementRoutineClient(new BattleShip(), in.nextLine(),
					server.fieldShipsPlayerTwo)) {
				out.println("false");
			}
			out.println("true");
			while (!server.shipPlacementRoutineClient(new Frigate(), in.nextLine(),
					server.fieldShipsPlayerTwo)) {
				out.println("false");
			}
			out.println("true");
			while (!server.shipPlacementRoutineClient(new Frigate(), in.nextLine(),
					server.fieldShipsPlayerTwo)) {
				out.println("false");
			}
			out.println("true");
			while (!server.shipPlacementRoutineClient(new Cruiser(), in.nextLine(),
					server.fieldShipsPlayerTwo)) {
				out.println("false");
			}
			out.println("true");
			while (!server.shipPlacementRoutineClient(new MineSearcher(), in.nextLine(),
					server.fieldShipsPlayerTwo)) {
				out.println("false");
			}
			out.println("true");
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}